<template>
  <div id="exportData">
    <el-date-picker style="display: block; margin-bottom: 15px;"
                    v-model="date"
                    type="date"
                    size="mini"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
    >
    </el-date-picker>
    <el-button type="primary" @click="exportAll" >导出所有数据</el-button>
    <el-button type="primary" @click="exportRisk" >导出健康风险数据</el-button>
    <el-button type="primary" @click="exportException">导出异常数据</el-button>
  </div>
</template>

<script>
import { downloadAllQuest, downloadRiskQuest,downloadExceptionQuest } from "@/network/index.js";
export default {
  name: "ExportData",
  data(){
    return{
      date:""
    }
  },
  methods:{
    exportAll(){
      let token = this.$store.getters.getToken;
      downloadAllQuest(token,this.date)
          .then((res) => {
            let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'})
            let url = window.URL.createObjectURL(blob)
            const link = document.createElement('a') // 创建a标签
            link.href = url
            link.download = `全部健康上报数据.xlsx` // 重命名文件
            link.click()
            URL.revokeObjectURL(url) // 释放内存
          })
          .catch((err) => {
            console.warn(err);
          });
    },
    exportRisk(){
      let token = this.$store.getters.getToken;
      downloadRiskQuest(token,this.date)
          .then((res) => {
            let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'})
            let url = window.URL.createObjectURL(blob)
            const link = document.createElement('a') // 创建a标签
            link.href = url
            link.download = `风险健康上报数据.xlsx` // 重命名文件
            link.click()
            URL.revokeObjectURL(url) // 释放内存
          })
          .catch((err) => {
            console.warn(err);
          });
    },
    exportException(){
      let token = this.$store.getters.getToken;
      downloadExceptionQuest(token,this.date)
          .then((res) => {
            let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'})
            let url = window.URL.createObjectURL(blob)
            const link = document.createElement('a') // 创建a标签
            link.href = url
            link.download = `异常健康上报数据.xlsx` // 重命名文件
            link.click()
            URL.revokeObjectURL(url) // 释放内存
          })
          .catch((err) => {
            console.warn(err);
          });
    },
  }
}
</script>

<style scoped>

</style>